from rest_framework.authentication import BasicAuthentication, SessionAuthentication
from rest_framework.filters import SearchFilter
from rest_framework.mixins import ListModelMixin
from rest_framework.pagination import PageNumberPagination
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

from movie.models import Movie
from movie.serializers import MovieListSerializer


class MoviePagination(PageNumberPagination):
    page_size = 1
    page_query_param = 'p'
    max_page_size = 2


class MovieListViewSet(ListModelMixin, GenericViewSet):

    queryset = Movie.objects.all()
    serializer_class = MovieListSerializer
    pagination_class = MoviePagination
    # pagination_class = LimitOffsetPagination

    authentication_classes = [BasicAuthentication, SessionAuthentication, JSONWebTokenAuthentication]
    # authentication_classes = [BasicAuthentication, TokenAuthentication]
    permission_classes = [IsAuthenticated]

    filter_backends = (SearchFilter,)
    search_fields = ('showname',)